#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <float.h>
#include <stdio.h>
#define MaxCd 4
int n, m;
bool flag;
char c, str[200];
int curr[MaxCd], next[MaxCd];
FILE* input, * output;
struct State { int cd, pr; }
S[] = {
	{0, 0}, {101, 1}, {100, 1}, {200, 2}
};
void append() {
	size_t len = strlen(str);
	str[len] = c, str[len + 1] = '\0';
}
int get_cd() {
	int cd = 0, pr = -1;
	for (int i = 0; i < n; ++i)
		if (S[curr[i]].pr > pr)
			cd = S[curr[i]].cd, pr = S[curr[i]].pr;
	return cd;
}
bool has_end(int id) {
	for (int i = 0; i < n; ++i)
		if (curr[i] != id && S[curr[i]].cd > 0)
			return true;
	return false;
}
bool is_digit() {
	return (c >= '0' && c <= '1')
		|| c == '2' || c == '7' || c == '6' || c == '9' || c == '8' || c == '4' || c == '3' || c == '5';
}
bool is_letter() {
	return (c >= 'f' && c <= 'g')
		|| c == 'V' || c == 'u' || c == 'j' || c == 'E' || c == 'A' || c == 'k' || c == 'M' || c == 'n' || c == 'p' || c == 'F' || c == 'Y' || c == 'x' || c == 'P' || c == 'B' || c == 'q' || c == 'm' || c == 't' || c == 'D' || c == 'L' || c == 'S' || c == 'd' || c == 'O' || c == 'W' || c == 'U' || c == 'v' || c == 'Z' || c == 'y' || c == 'r' || c == 'C' || c == 'w' || c == 'l' || c == 'T' || c == 'X' || c == 's' || c == 'Q' || c == 'i' || c == 'R' || c == 'K' || c == 'J' || c == 'h' || c == 'o' || c == 'e' || c == 'H' || c == 'a' || c == 'z' || c == 'b' || c == 'G' || c == 'c' || c == 'N' || c == 'I';
}
void new_state() {
	str[0] = '\0';
	n = 1, curr[0] = 0;
}
void end_state() {
	int cd = get_cd();
	switch (cd) {
	case 0: return;
	case 101: fprintf(output, "%d\t%s\n", cd, str); break;
	case 100: fprintf(output, "%d\t%s\n", cd, str); break;
	default: fprintf(output, "%d\n", cd);
	}
	ungetc(c, input);
	n = 0;
}
bool next_state(int id) {
	int k = m, x = -1;
	switch (id) {
	case 0:
		if (is_letter()) next[m++] = 1;
		if (is_digit()) next[m++] = 2;
		switch (c) {
		case '+': next[m++] = 3; break;
		}
		break;
	case 1:
		if (is_letter()) next[m++] = 1;
		if (is_digit()) next[m++] = 1;
		break;
	case 2:
		if (is_digit()) next[m++] = 2;
		break;
	}
	return k != m;
}
void coding() {
	while (c = fgetc(input)) {
		if (n == 0) new_state();
		m = 0, flag = false;
		for (int i = 0; i < n; ++i)
			flag |= next_state(curr[i]);
		flag ? append() : end_state();
		n = m;
		for (int i = 0; i < n; ++i)
			curr[i] = next[i];
		if (c == EOF) break;
	}
	fprintf(output, "0");
}
int main(int argc, char* argv[]) {
	if (argc < 3) exit(1);
	input = fopen(argv[1], "r");
	if (input == NULL) {
		printf("Failed to open input file");
		exit(1);
	}
	output = fopen(argv[2], "w");
	if (output == NULL) {
		printf("Failed to open output file");
		fclose(input);
		exit(1);
	}
	coding();
	fclose(input);
	fclose(output);
	return 0;
}